<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/7/24
 * Time: 13:21
 */

namespace app\service;


use app\api\controller\SmsCode;
use phpmailer\BaseException;
use Redis\Redis;
use think\Db;

/**
 * 用户服务层
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月24日13:22:12
 */
class MemberService extends BaseService
{
    /**
     * 用户列表条件
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月24日13:22:12
     * @param    [array]          $params [输入参数]
     */
    public static function MemberListWhere($params = [])
    {

        $where = [];
//            if(!empty($params['keywords']))
//            {
//                $where[] =['username|nickname|mobile', 'like', '%'.$params['keywords'].'%'];
//            }

            if(!empty($params['phone']))
            {
                $where[] =['phone', 'like', '%'.$params['phone'].'%'];
            }
            // 省市区
            if(!empty($params['province']))
            {
                $where[] = ['province', '=', $params['province']];
            }
            if(!empty($params['city']))
            {
                $where[] = ['city', '=', $params['city']];
            }
            if(!empty($params['area']))
            {
                $where[] = ['area', '=', $params['area']];
            }

            // 状态
            if(isset($params['status']) && $params['status'] > 0)
            {
                $where[] = ['status', '=', intval($params['status'])];
            }

        // id
            if(isset($params['id_arr']) && !empty($params['id_arr']))
            {
               $where[] = ['id', 'in', explode(',',$params['id_arr'])];
            }

             $where[] = ['is_delete', '=', 2];


        return $where;
    }


    /**
     * 用户总数
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月24日13:22:12
     * @param    [array]          $where [条件]
     */
    public static function MemberTotal($where)
    {
        return (int) Db::name('member')->where($where)->count();
    }


    /**
     * 获取用户
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月24日13:29:47
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function MemberList($params = [])
    {
        $params['table']='member';
        $data = self::DataList($params);
        return self::DataDealWith($data);

    }


    /**
     * 数据处理
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月24日13:30:30
     * @desc    description
     * @param   [array]          $data [用户数据数据 二维数组]
     */
    public static function DataDealWith($data,$is_detail=false){

        if(!empty($data) && is_array($data))
        {
            foreach($data as &$v)
            {
                if(is_array($v))
                {

                    //pop_imgurl
                    if(isset($v['pop_imgurl']))
                    {

                        $v['pop_imgurl'] = ResourceService::AttachmentPathViewHandle($v['pop_imgurl'],true);
                    }

                    //上下架时间
                    if(isset($v['status']))
                    {
                        //已注册
                        if(1== $v['status'])
                        {
                            $v['status_title']='已注册';
                            //已注册
                        }elseif(2== $v['status'])
                        {
                            $v['status_title']='未注册';
                        }else{
                            $v['status_title']='已下单';
                        }
                    }

                    if(isset($v['province'])&&isset($v['city'])&&isset($v['area']))
                    {
                        $v['address_total']=$v['province'].$v['city'].$v['area'];
                    }
                    //用户消费订单
                    if ($is_detail)
                    {
                        $order_where=[
                            'member_id'=>$v['id'],
                            'pay_status'=>1,
                            'member_orderdetail.is_delete'=>2,
                        ];
                        $order=Db::name('member_order')->join('member_orderdetail','member_order.id=member_orderdetail.order_id')->where($order_where)->field('member_order.create_time,total_num,member_order.id,total_price,order_number,bizpro_name,bizpro_number,buy_num,order_id')->select();
                        $v['order_arr']=$order;
                    }
                    //用户消费金额
                    if(isset($v['id']))
                    {
                        $where=[['member_id','=',$v['id']],['pay_status','=',1],['member_id','=',$v['id']]];
                        $v['total_price']=Db::name('member_order')->where($where)->sum('pay_price');
                    }

                }
            }

        }

        return DataReturn('获取成功',0,$data);
    }



    /**
     * app用户注册或修改绑定手机
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月5日14:30:00
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function AppReg($params = [])
    {
        // 数据验证
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'phone',
                'error_msg'         => '手机号码不能为空',
                'error_code' => 1007,
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'verify',
                'error_msg'         => '验证码不能为空',
                'error_code' => 1008,
            ],
//            [
//                'checked_type'      => 'empty',
//                'key_name'          => 'openId',
//                'error_msg'         => 'openId不能为空',
//                'error_code' => 1008,
//            ]

        ];

        $ret = ParamsChecked($params, $p);

        if(true !== $ret)
        {
            $error_arr = explode(',', $ret);
            throw new BaseException(['code'=>403 ,'errorCode'=>$error_arr[1],'msg'=>$error_arr[0],'status'=>false,'debug'=>false ]);
        }
        // 手机号码格式
        if(!CheckMobile($params['phone']))
        {

            throw new BaseException(['code'=>403 ,'errorCode'=>1006,'msg'=>'手机号码格式错误','status'=>false,'debug'=>false ]);

        }

        $redis = new Redis();

        # 从redis中获取改手机号是否存在验证码
        $codeNum = $redis->hGet('SmsCode', $params['phone']);

        if($codeNum != $params['verify'] or empty($codeNum))
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>1004,'msg'=>'验证码错误','status'=>false,'debug'=>false ]);
        }
        // 用户数据
        $data = array(
            'phone'             =>$params['phone'],
            //'openid'            =>$params['openId'],
            //'unionid'           =>$params['unionid'],
        );

        //$where=isset($params['member_id'])?[['id', '=', $params['member_id']],]:[['unionid', '=', $params['unionid']],];


        $where=[];
        if(isset($params['member_id'])){
            $where[]= ['id', '=', $params['member_id']];
        }

        if(isset($params['unionId'])){
            $where[]= ['unionid', '=', $params['unionId']];
        }

        if(isset($params['openId'])){
            $where[]= ['openid', '=', $params['openId']];
        }
        //app openid_app
        if(isset($params['openId_app'])){
            $where[]= ['openid_app', '=', $params['openId_app']];
        }

        if(isset($params['phone'])){
            $where[]= ['phone', '=', $params['phone']];
        }
        #用户id为空的时候是注册
        if(empty($params['member_id'])){
            // 获取用户信息
            $userInfo = Db::name('member')->where(array("unionid"=>$params['unionId']))->find();
            if(!empty($userInfo)){
                //说明有用户信息 提示 你已经注册过了  请不要重复注册
                throw new BaseException(['code'=>403 ,'errorCode'=>1016,'msg'=>'你已经注册过了  请不要重复注册','status'=>false,'debug'=>false ]);

            }
        }
        // 获取用户信息
        $temp_user = Db::name('member')->where($where)->find();


        // 额外信息
        if(empty($temp_user['openid']) && !empty($params['openId']))
        {
            $data['openid'] = $params['openId'];
        }
        //qpp 的openid
        if(empty($temp_user['openid_app']) && !empty($params['openId_app']))
        {
            $data['openid_app'] = $params['openId_app'];
        }

        if(empty($temp_user['unionid']) && !empty($params['unionid']))
        {
            $data['unionid'] = $params['unionid'];
        }

        if(empty($temp_user['name']) && !empty($params['name']))
        {
            $data['name'] = $params['name'];
        }
        if(empty($temp_user['headpic']) && !empty($params['headpic']))
        {
            $data['headpic'] = $params['headpic'];
        }
        if(empty($temp_user['province']) && !empty($params['province']))
        {
            $data['province'] = $params['province'];
        }
        if(empty($temp_user['city']) && !empty($params['city']))
        {
            $data['city'] = $params['city'];
        }
        if(empty($temp_user['area']) && !empty($params['area']))
        {
            $data['area'] = $params['area'];
        }
        if(empty($temp_user['client_id']) && !empty($params['client_id']))
        {
            $data['client_id'] = $params['client_id'];
        }
        //根据经纬度获取区城市信息
        if( empty($temp_user['area']) &&(!empty($params['lon'])&&!empty($params['lat'])) )
        {

            $result =  getAddressComponent($params['lon'], $params['lat'], 1);
            $data['area'] = $result['result']['addressComponent']['district'];
            $data['city'] = $result['result']['addressComponent']['city'];
            $data['province'] = $result['result']['addressComponent']['province'];
        }

//        if(!empty($params['ish5']))
//        {
//            $data['ish5'] = $params['ish5'];
//        }
        $data['ish5'] = isset($params['ish5'])?$params['ish5']:2;
        if(empty($temp_user['unionid']) && !empty($params['unionId']))
        {
            $data['unionid'] = $params['unionId'];
        }
//        if(!isset($data['ish5']))
//        {
//            $data['ish5']=2;
//        }

        // 不存在添加/存在则更新
        $return_msg='注册成功';
        $data['status']=1;
        if(empty($temp_user))
        {
            $user_id = Db::name('member')->insertGetId($data);
            //用户登录日志
            self::VerifyLogMember(['member_id'=>$user_id,'create_time'=>date('Y-m-d',time())]);
        } else {

//            if($temp_user['id']==$params['member_id'])
//            {
//                $return_msg='重置成功,请重新登录';
//                $user_id=Db::name('member')->where('id='.$temp_user['id'])->update($data);
//                self::LogOut(['token'=>$params['token']]);
//            }else{
//
//                if(!empty($temp_user['phone'])&&strlen($temp_user['phone'])>1)
//                {
//                    throw new BaseException(['code'=>403 ,'errorCode'=>1003,'msg'=>'手机号已被注册','status'=>false,'debug'=>false ]);
//                }
//            }
            if($temp_user['id']==$params['member_id'])
            {
                $return_msg='重置成功,请重新登录';
            }
            if(!empty($temp_user['phone'])&&strlen($temp_user['phone'])>1)
            {
                throw new BaseException(['code'=>403 ,'errorCode'=>1003,'msg'=>'手机号已被注册','status'=>false,'debug'=>false ]);
            }


            $user_id=Db::name('member')->where('id='.$temp_user['id'])->update($data);

            self::LogOut(['token'=>$params['token']]);

        }

        if(isset($user_id) && $user_id > 0)
        {
            // 清除验证码
            $redis->hDel('SmsCode',$params['phone']);
            $temp_user = Db::name('member')->where($where)->find();
            $cache=cache(self::AppMemberInfoHandle($temp_user['id']));


            return  DataReturn($return_msg,0,
                [
                    'token'=>self::AppMemberInfoHandle($temp_user['id']),
                    'nickName'=>$cache['name'],
                    'avatarUrl'=>$cache['headpic'],
                    'unionId'=>$cache['unionid'],
                    'openId'=>$cache['openid'],
                    'phone'=>$cache['phone'],
                ]
            );

        } else {
            throw new BaseException(['code'=>403 ,'errorCode'=>1017,'msg'=>'绑定失败','status'=>false,'debug'=>false ]);
        }
    }

    /**
     * app用户绑定验证码发送
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月5日14:30:00
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function AppUserBindVerifySend($params = [])
    {

        // 数据验证
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'phone',
                'error_msg'         => '手机号码不能为空',
                'error_code' => 1001,
            ],
            [
                'checked_type'      => 'fun',
                'key_name'          => 'phone',
                'checked_data'      => 'CheckMobile',
                'error_msg'         => '手机号码格式错误',
                'error_code' => 1002,
            ],
        ];


        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            $error_arr = explode(',', $ret);
            throw new BaseException(['code'=>403 ,'errorCode'=>$error_arr[1],'msg'=>$error_arr[0],'status'=>false,'debug'=>false ]);

        }

        #注册的情况
        if($params['mark'] == 'register'){
            // 获取用户信息
            $temp_user = Db::name('member')->where([['phone', '=', $params['phone']],])->field('id,name,headpic,phone,openid,unionid')->find();
            if(!empty($temp_user['phone'])&&strlen($temp_user['phone'])>1)
            {
                throw new BaseException(['code'=>403 ,'errorCode'=>1003,'msg'=>'手机号已被注册','status'=>false,'debug'=>false ]);
            }
        }
        #登录的情况
        if($params['mark'] == 'login'){
            // 获取用户信息
            $temp_user = Db::name('member')->where([['phone', '=', $params['phone']],])->field('id,name,headpic,phone,openid,unionid')->find();
            if(empty($temp_user['phone']))
            {
                throw new BaseException(['code'=>403 ,'errorCode'=>1003,'msg'=>'您还未注册！','status'=>false,'debug'=>false ]);
            }
        }



        $status= self::getSmsCode($params['phone']);

        // 状态
        if($status['status'])
        {
            return json(DataReturn('发送成功', 0,['code'=>$status['num']]));
        } else {
            throw new BaseException(['code'=>403 ,'errorCode'=>1005,'msg'=>$status['msg'],'status'=>false,'debug'=>false ]);
        }
    }

    /**
     * 验证登陆时间
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月5日14:30:00
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function VerifyLogMember($params){
        $where=[
            'member_id'=>$params['member_id'],
        ];
       $create_time=Db::name('log_member')->where($where)->value('create_time');
       if(substr($create_time,0,10)!=$params['create_time'])
       {
           return   Db::name('log_member')->insertGetId(['member_id'=>$params['member_id']]);
       }
       return true;
    }

    /*
     * 用户登录
     */
    public static function AppLogin($params){
        // 数据验证
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'phone',
                'error_msg'         => '手机号码不能为空',
                'error_code' => 30007,
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'verify',
                'error_msg'         => '验证码不能为空',
                'error_code' => 30007,
            ],

        ];
        $ret = ParamsChecked($params, $p);

        if(true !== $ret)
        {

            $error_arr = explode(',', $ret);
            throw new BaseException(['code'=>403 ,'errorCode'=>$error_arr[1],'msg'=>$error_arr[0],'status'=>false,'debug'=>false ]);
        }

        // 手机号码格式
        if(!CheckMobile($params['phone']))
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>99999,'msg'=>'手机号码格式错误','status'=>false,'debug'=>false ]);

        }


        $redis = new Redis();
        # 从redis中获取改手机号是否存在验证码
        $codeNum = $redis->hGet('SmsCode', $params['phone']);
        if($codeNum != $params['verify'] or empty($codeNum))
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>1004,'msg'=>'验证码错误','status'=>false,'debug'=>false ]);
        }

        // 用户数据
        $data = array(
            'phone'            => $params['phone'],
            'status'           =>1
        );

        // 获取用户信息
        $temp_user = Db::name('member')->where([['phone', '=', $data['phone']],])->field('id,name,headpic,phone,openid,unionid,openid_app,area,client_id')->find();

        if($temp_user)
        {
            //更新openid
            $data=[];

            $data['ish5']=isset($params['ish5'])?$params['ish5']:2;
            if(isset($params['openId'])&&strlen($temp_user['openid'])==1)
            {
                Db::name('member')->where([['phone', '=', $data['phone']],])->update($data);
            }
            if(isset($params['client_id'])&&strlen($temp_user['client_id']) ==0 or isset($params['area'])&&strlen($temp_user['area'])==0)
            {
                $result =  getAddressComponent($params['lon'], $params['lat'], 1);
                $params['area'] = $result['result']['addressComponent']['district'];
                $params['city'] = $result['result']['addressComponent']['city'];
                $params['province'] = $result['result']['addressComponent']['province'];
                $a = Db::name('member')->where(array('phone'=>$params['phone']))->update(array(
                    "province"=>$params['province'],
                    "city"=>$params['city'],
                    "area"=>$params['area'],
                    "client_id"=>$params['client_id'],
                ));
            }

            return  DataReturn('登录成功', 0,
                [
                    'token'=>self::AppMemberInfoHandle($temp_user['id']),
                    'nickName'=>$temp_user['name'],
                    'avatarUrl'=>$temp_user['headpic'],
                    'unionId'=>$temp_user['unionid'],
                    'openId'=>$temp_user['openid'],
                    'openId_app'=>$temp_user['openid_app'],
                    'phone'=>$temp_user['phone'],
                    'area'=>$temp_user['area'],
                    'client_id'=>$temp_user['client_id'],
                ]);
        }else{
            throw new BaseException(['code'=>403 ,'errorCode'=>1009,'msg'=>'您还未注册!','status'=>false,'debug'=>false ]);
        }

    }


    /**
     * 用户状态校验
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2019-02-27
     * @desc    description
     * @param   [string]          $field [条件字段]
     * @param   [string]          $value [条件值]
     */
    public static function MemberStatusCheck($field, $value)
    {
        return true;
        // 查询用户状态是否正常
        $user = self::MemberInfo($field, $value);

        if(empty($user))
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>1011,'msg'=>'用户不存在','status'=>false,'debug'=>false ]);
        }
        if($user['status']!=1||$user['is_delete']==1)
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>1012,'msg'=>'用户状态有误','status'=>false,'debug'=>false ]);

        }
        return DataReturn('正常', 0);
    }

    /**
     * 根据字段获取用户信息
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2019-01-25
     * @desc    description
     * @param   [string]          $where_field      [字段名称]
     * @param   [string]          $where_value      [字段值]
     * @param   [string]          $field            [指定字段]
     */
    public static function MemberInfo($where_field, $where_value, $field = '*')
    {
        if(empty($where_field) || empty($where_value))
        {
            return '';
        }

        return Db::name('member')->where([$where_field=>$where_value])->field($field)->find();
    }


    /**
     * 获取用户登录信息
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2019-02-27
     * @desc    description
     */
    public static function LoginMemberInfo($params)
    {



        // 用户数据处理
        $user = null;

        if(!empty($params['token']))
        {

            $user = cache($params['token']);

            if($user !== null && isset($user['id']))
            {
                return $user;
            }

            // 数据库校验
            return self::AppMemberInfoHandle(null, 'token', $params['token']);
        }

        return $user;
    }


    /**
     * app用户信息
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2018-11-06
     * @desc    description
     * @param   [int]             $member_id          [指定用户id]
     * @param   [string]          $where_field      [字段名称]
     * @param   [string]          $where_value      [字段值]
     * @param   [array]           $user             [用户信息]
     */
    public static function AppMemberInfoHandle($member_id = null, $where_field = null, $where_value = null, $member = [])
    {
        // 获取用户信息

        $field = 'id,name,phone,openid,headpic,unionid';
        if(!empty($member_id))
        {
            $member = self::MemberInfo('id', $member_id, $field);
        } elseif(!empty($where_field) && !empty($where_value) && empty($member))
        {
            $member = self::MemberInfo($where_field, $where_value, $field);
        }

        if(!empty($member))
        {
            // 用户信息处理
            // token生成并存储缓存
            if($member['is_mandatory_bind_mobile'] == 0 || ($member['is_mandatory_bind_mobile'] == 1 && !empty($member['phone'])))
            {
                $member['token'] = config('leebridge.cache_user_info').$member['phone'];
                    //md5(md5($member['id'].time()).rand(100, 1000000));
                //cache(config('leebridge.cache_user_info').$member['token'], $member);
                cache($member['token'], $member);


            } else {
                $member['token'] = '';
            }


            // 用户登录纪录处理
            self::VerifyLogMember($member['id'], true);
        }

        //return config('leebridge.cache_user_info').$member['token'];
        return $member['token'];
    }




    /**
     * 获取用户展示信息
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [int]          $user_id     [用户id]
     * @param   [array]        $user        [指定用户信息]
     * @param   [boolean]      $is_privacy  [是否隐私处理展示用户名]
     */
    public static function GetUserViewInfo($user_id, $user = [], $is_privacy = false)
    {
        // 是否指定用户信息
        if(empty($user) && !empty($user_id))
        {
            $user = Db::name('member')->field('name,id,phone')->find($user_id);
        }

        // 用户数据处理
        //$user = self::UserHandle($user);

        return $user;
    }

    /**
     * 发送短信验证码
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [string]          $phone     [用户手机号]
     */
    //焦云发送
    public static function  getSmsCode($phone){

        $sms = new SmsCode();

        #把验证码存一下redis
        $redis = new Redis();

        # 从redis中获取改手机号是否存在验证码
        $codeNum = $redis->hGet('SmsCode', $phone);

        if ($codeNum) {
            # 存在验证码
            $code = $sms->JyCode($phone, $codeNum);
            if (!empty($code) and $code['status'] == true) {
                return array('status' => true, 'num' => $code['code'], 'msg' => '验证码发送成功');
            } else {
                return array('status' => false, 'msg' => $code['msg']);

            }
        } else {

            $code = $sms->JyCode($phone, randCodes());

            if (!empty($code) and $code['status'] == true) {
                $redis->hSet('SmsCode', $phone, $code['code'], '1800');
                return array('status' => true, 'num' => $code['code'], 'msg' => '验证码发送成功');
            } else {
                return array('status' => false, 'msg' => $code['msg']);
            }
        }
    }
    //云之讯发送短信验证码
  /*public static function  getSmsCode($phone){
        $sms = new SmsCode();

        #把验证码存一下redis
        $redis = new Redis();

        # 从redis中获取改手机号是否存在验证码
        $codeNum = $redis->hGet('SmsCode', $phone);

        if ($codeNum) {
            # 存在验证码
            $code = $sms->Ysms($phone, $codeNum);
            if (!empty($code) and $code['status'] == true) {
                return array('status' => true, 'num' => $code['code'], 'msg' => '验证码发送成功');
            } else {
                return array('status' => false, 'msg' => '验证码发送失败');

            }
        } else {

            $code = $sms->Ysms($phone, randCodes());

            if (!empty($code) and $code['status'] == true) {
                $redis->hSet('SmsCode', $phone, $code['code'], '1800');
                return array('status' => true, 'num' => $code['code'], 'msg' => '验证码发送成功');
            } else {
                return array('status' => false, 'msg' => '验证码发送失败');
            }
        }
    }*/

    /**
     * 浏览日志
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [string]          $params     [参数]
     */
  public static function LogBrowse($params){

      $re = Db::name('log_browse')->alias('lb')
          ->join(['bizpro'=>'b'], 'b.id=lb.bizpro_id')
          ->join(['standard_detail'=>'sd'], 'b.id=sd.bizpro_id')
          ->group('b.id')
          ->where('member_id='.$params['member_id'])->field('b.imgurl,b.name,b.label,b.old_price,sd.standard_desc,sd.bizpro_id')->order('lb.browse_num desc')->select();

//'member_id='.$params['member_id']
      # 处理数据
      if(!empty($re))
      {
        $data=BizproService::BizDataDealWith($re);

        foreach ($data['data'] as &$v)
        {
            unset( $v['standard_desc']);
            unset( $v['sale_price_max']);

        }
      }
      return DataReturn('获取成功','0',$data['data']);
  }


    /**
     * 退出登录
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [string]          $params     [参数]
     */
  public static function LogOut($params)
  {
      cache($params['token'],null);
      return true;
  }

    /**
     * 新增浏览日志
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [string]          $params     [参数]
     */
  public static function SaveLogBrowse($params)
  {
      if(!isset($params['member_id']))
      {
       return true;
      }
     $log= Db::name('log_browse')->where($params)->find();

      if($log)
      {

          return true;
//         $re = Db::name('log_browse')->where($params)->setInc('browse_num',1);
      }else{
//          var_($log);exit;
          $re = Db::name('log_browse')->insertGetId($params);
      }
      if(!$re)
      {
          throw new BaseException(['code'=>403 ,'errorCode'=>1010,'msg'=>'添加浏览记录失败','status'=>false,'debug'=>false ]);
      }
  }

    /**
     * 更新用户数据
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年8月6日10:15:36
     * @desc    description
     * @param   [string]          $param     [参数]
     * @param       [int]            $id      [用户id]
     */
  public static function UpdateInfo($id,$param)
  {
      if(!empty($param['headpic'])){
          Db::name('member')->where('phone='.$param['phone'])->update($param);

      }
      $temp_user=Db::name('member')->where('phone='.$param['phone'])->find();

      return  DataReturn('登录成功', 0,
          [
              'nickName'=>$temp_user['name'],
              'avatarUrl'=>$temp_user['headpic'],
              'unionId'=>$temp_user['unionid'],
              'openId'=>$temp_user['openid'],
              'phone'=>$temp_user['phone'],
          ]);
  }

}